import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    redirect: {name:'Loginvuex'}
  },
  {
    path: '/about',
    name: 'about',
    component: () => import( '../views/AboutView.vue'),
    children:[
      {
        path: '/users',
        name: 'users',
        component: () => import( '../views/list/usersone.vue'),
        meta: {
          title:"用户管理> 用户列表"
        }
      },
      {
        path: '/roles',
        name: 'roles',
        component: () => import( '../views/list/roles.vue'),
        meta: {
          title:"权限管理> 角色列表"
        }
      },
      {
        path: '/categories',
        name: 'categories',
        component: () => import( '../views/list/categories.vue'),
        meta: {
          title:"商品管理> 商品分类"
        }
      },
      {
        path: '/params',
        name: 'params',
        component: () => import( '../views/list/params.vue'),
        meta: {
          title:"商品管理>分类参数"
        }
      },
      {
        path: '/goods',
        name: 'goods',
        component: () => import( '../views/list/goods.vue'),
        meta: {
          title:"商品管理>商品列表"
        }
      },
      {
        path: '/add',
        name: 'add',
        component: () => import( '../views/list/add.vue'),
        meta: {
          title:"商品管理>添加参数"
        }
      },
      {
        path: '/reports',
        name: 'reports',
        component: () => import( '../views/list/reports.vue'),
        meta: {
          title:">添加参数"
        }
      },

    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import( '../views/login.vue')
  },
  {
    path: '/Loginvuex',
    name: 'Loginvuex',
    component: () => import( '../views/Loginvuex.vue')
  },
  {
    path: '/Menu',
    name: 'Menu',
    component: () => import( '../views/Menu.vue')
  },
]

// 路由守卫

const router = new VueRouter({
  routes
})

import {routerList} from "@/utils/routerList.js"

function loadRoute() {
  let token=localStorage.getItem("token")
  let MenuLists=JSON.parse(localStorage.getItem("MenuList"))
  if(token && MenuLists){
    let newlist=routerList(MenuLists)
    newlist.forEach(element => {
      router.addRoute("home",element)
    });
  }
}
loadRoute()
export default router
